home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / PowerPlant / LProgressIndicator & Friends / LProgressIndicator / LProgressIndicator.cp next >
Encoding:
Text File  |  1996-04-12  |  2.5 KB  |  99 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        LProgessIndicator.cp
  3.  
  4.     Contains:    Abstract base class for the display of progress
  5.                 to the user.
  6.                 
  7.                 Insulates a calling entity from the the details of the
  8.                 method used to display the progress to the user.  IOW,
  9.                 isolation of the user interface from low-level code.
  10.                 
  11.                 Generally, you'll pass an LProgressIndicator subclass to
  12.                 some piece of code which only knows about this abstract
  13.                 class, and it will call the CompletedThisMuch() functions
  14.                 to indicate the total amount of the task completed. This
  15.                 removes the burden of displaying progress to the user from
  16.                 the shoulders of the independent code module writer, and
  17.                 allows you to implement consistent feedback throughout
  18.                 your application using your preferred interface.
  19.                 
  20.                 Uses PowerPlant naming conventions, but doesn't require
  21.                 PowerPlant.
  22.                 
  23.     Version:    2.0
  24.  
  25.     Author:        Chris K. Thomas, ckt@best.com
  26.     
  27.     Copyright:    ©1995 Chris K. Thomas.  All Rights Reserved.
  28. */
  29.  
  30. // * includes
  31. #include "LProgressIndicator.h"
  32.  
  33. // * default constructor
  34. LProgressIndicator::
  35. LProgressIndicator()
  36. {
  37.     mTaskType = task_Indeterminate;
  38.     mMinValue = 0;
  39.     mMaxValue = 100;
  40.     mCurValue = 0;
  41. }
  42.  
  43. // * immediate constructor
  44. LProgressIndicator::
  45. LProgressIndicator(ETaskType inTaskType, SInt32 inMin, SInt32 inMax, SInt32 inStartMax)
  46. {
  47.     mTaskType = inTaskType;
  48.     mMinValue = inMin;
  49.     mMaxValue = inMax;
  50.     mCurValue = inStartMax;
  51. }
  52.  
  53. LProgressIndicator::~LProgressIndicator()
  54. {
  55.     
  56. }
  57.  
  58. // * Making progress absolutely
  59. void LProgressIndicator::CompletedThisMuch(SInt32 inThisMuch)
  60. {
  61.     //
  62.     // threshold - if you don’t want a DebugStr when/if you go
  63.     // over the MaxValue or under the MinValue, comment out the
  64.     // SignalPStr lines.  If the task is measured, we don’t need
  65.     // to threshold.  SignalPStr is a no-op when PowerPlant
  66.     // debugging is off.
  67.     //
  68.     if(GetTaskType() == task_Measured)
  69.     {
  70.         if(inThisMuch > GetMaxValue())
  71.         {
  72.             SignalPStr_("\pLProgressIndicator: I've been passed a current value greater than the maximum value.");
  73.             return;
  74.         }
  75.         else if(inThisMuch < GetMinValue())
  76.         {
  77.             SignalPStr_("\pLProgressIndicator: I've been passed a current value less than the minimum value.");
  78.             return;
  79.         }
  80.     }
  81.     
  82.     mCurValue = inThisMuch;
  83.     ValueChanged();
  84. }
  85.  
  86. // * Making progress incrementally
  87. void LProgressIndicator::CompletedThisMuchMore(SInt32 inThisMuchMore)
  88. {
  89.     CompletedThisMuch(mCurValue + inThisMuchMore);
  90. }
  91.  
  92. // * derived classes override this usually
  93. void LProgressIndicator::ValueChanged()
  94. {
  95.     // * this could be pure virtual...
  96. }
  97.  
  98.  
  99.